/*********************************
File name:  essraw.do
DATE:		3/2024
PURPOSE:    1. Drop parties that did not make into parliament
            2. Sort into party families 
INPUT: 		ESS1-10.dta
OUTPUT:		1. ESSorigin.dta
			2. Figure 1a Figure 1b
			2. Figure F1a Figure F1b
LOG FILE:   essraw.log
AUTHOR:     Odelia Oshri, Orit Kedar, Lotem Halevy, 
*********************************/
use  "C:\Users\User\Downloads\ess1-10.dta", clear
capture log using "essraw.log", replace
cd "C:\Users\User\Desktop\Figures"
set more off
*A. cleaning the data file

* Recode gender (male=1)**
tab gndr
recode gndr 2=0 1=1
drop if gndr>1
tab gndr
label define gndr 0 "F" 1 "M", replace
label values gndr gndr
tab gndr

* Turn variable "essround" into "Year" 
gen year=.
replace year=2002 if essround==1
replace year=2004 if essround==2
replace year=2006 if essround==3
replace year=2008 if essround==4
replace year=2010 if essround==5
replace year=2012 if essround==6
replace year=2014 if essround==7
replace year=2016 if essround==8
replace year=2018 if essround==9
replace year=2020 if essround==10

* Kepp Western European Countries** /*we're left with 18 countries*/
keep if cntry=="AT"|cntry=="BE"|cntry=="CH"|cntry=="DE"|cntry=="DK"|cntry=="ES"|cntry=="FI"|cntry=="FR"|cntry=="GB"|cntry=="GR"|cntry=="IE"|cntry=="IT"|cntry=="LU"|cntry=="NL"|cntry=="NO"|cntry=="PT"|cntry=="SE"|cntry=="IS"

**Drop non voters**
bys gndr: ta vote /*no difference found between % men and % women who vote ~ 74%*/
keep if vote==1

/* 1. Drop parties that didn't make it into parliament in 
	  the relevant countryear */ 
/* parliament composition is taken from ParlGov*/
/* Q wording: "party voted for in the last national election"*/
*Austria*
keep if (prtvtat<5 | prtvtat==.)
keep if (prtvtaat<6 | prtvtaat==.)
keep if (prtvtbat<4 | prtvtbat==5|  prtvtbat==7| prtvtbat==9| prtvtbat==.)
keep if (prtvtcat<4 |prtvtcat==5|prtvtcat==7) |prtvtcat==. 
*Belgium*
keep if (prtvtbe>=2 & prtvtbe<=6 | prtvtbe==8 | (prtvtbe<=14 & prtvtbe>=11) | prtvtbe==.) /*2002*/
keep if (prtvtabe==2 | prtvtabe==3 | prtvtabe==5 | (prtvtabe>=7 & prtvtabe<=13) | ///
	 prtvtabe==.) /*2004-2006*/
keep if (prtvtbbe<=13 | prtvtbbe==.) /*2008*/
keep if  (prtvtcbe<=5| (prtvtcbe>=8 & prtvtcbe<=13) | prtvtcbe==15|  prtvtcbe==. )    /*2010-2016*/
keep if (prtvtdbe<4| (prtvtdbe>=5 & prtvtdbe<=10)| prtvtdbe>=12|  prtvtdbe==. ) 
keep if (prtvtebe<=11|   prtvtebe==. ) 
 
*Switzerland* 
keep if ((prtvtch>=1 & prtvtch<=5) | prtvtch==7 | prtvtch==8 | (prtvtch<=12& prtvtch>=10) | prtvtch==15| prtvtch==.  )/*2002-2004*/
keep if ((prtvtach>=1 & prtvtach<=5) | prtvtach==7 | prtvtach==8 | (prtvtach<=12& prtvtach>=10) | prtvtach==15| prtvtach==.  ) /*2006*/
keep if (prtvtbch<=9 | prtvtbch<=13&prtvtbch>=11 | prtvtbch==. ) /*2008*/
keep if (prtvtcch<=13 | prtvtcch==. ) /*2010*/
keep if (prtvtdch<=8 | prtvtdch==10 | prtvtdch==12| prtvtdch==.) /*2012*/
keep if (prtvtech<=8 |  prtvtech==10 | prtvtech==12 |prtvtech==.) /*2014*/
keep if (prtvtfch<=8  | prtvtfch==10 | prtvtfch==11 | prtvtfch==. ) /*2016*/
keep if (prtvtgch<=10| prtvtgch==.) /*2018*/
keep if (prtvthch<=11| prtvthch==.) /*2020*/

*Germany*
keep if (prtvde2<=5  | prtvde2==.  ) /*2002*/
keep if (prtvade2<=5 | prtvade2==. ) /*2004*/
keep if (prtvbde2<=5 | prtvbde2==. ) /*2006-2008*/
keep if (prtvcde2<=5 | prtvcde2==. ) /*2010*/
keep if (prtvdde2<=5 | prtvdde2==. ) /*2012*/
keep if (prtvede2<=4 | prtvede2==. ) /*2014-2018*/
keep if (prtvfde2<=6 | prtvfde2==. ) /*2020*/

*Denmark*
keep if (prtvtdk<=3 |(prtvtdk<=8 & prtvtdk>=5) | prtvtdk==10 | prtvtdk==.) /*2002-2004*/
keep if (prtvtadk<=3 |prtvtadk==5 | prtvtadk==6 | prtvtadk==8 | prtvtadk==10 |  prtvtadk==.) /*2006*/	
keep if (prtvtbdk<=5 |(prtvtbdk<=9 & prtvtbdk>=7) | prtvtbdk==.) /*2008-2010*/
keep if (prtvtcdk<=5 |(prtvtcdk<=9 & prtvtcdk>=7) | prtvtcdk==.) /*2012-2014*/
keep if (prtvtddk<=5 |(prtvtddk<=10 & prtvtddk>=7) | prtvtddk==.) /*2018*/

*Spain*
keep if (prtvtes<=12  | prtvtes==.  ) /*2002*/
keep if (prtvtaes<=5 | prtvtaes<=10& prtvtaes>=7| prtvtaes==12| prtvtaes== 13 | prtvtaes==. ) /*2004-2006*/
keep if (prtvtbes<=10 | prtvtbes==. ) /*2008-2010*/
keep if (prtvtces<=12 | prtvtces==. ) /*2012-2014*/
keep if (prtvtdes<=8 | prtvtdes==10 | prtvtdes==11 | prtvtdes==13 | prtvtdes==14 | prtvtdes==16| prtvtdes==. ) /*2016*/
keep if (prtvtees<=3 | prtvtees==5 | prtvtees==10 | prtvtees==. ) /*2018*/
keep if (prtvtfes<=4 | prtvtfes==6 | prtvtfes==8 | prtvtfes==. ) /*2020*/

*Finland*
keep if (prtvtfi<=2 | (prtvtfi>=4 & prtvtfi<=6) | (prtvtfi>=8 & prtvtfi<=10) | ///
		 prtvtfi==.) /*2002-2006*/
keep if (prtvtafi<=2 | (prtvtafi>=4 & prtvtafi<=9) | prtvtafi==.) /*2008*/
keep if (prtvtbfi<=2 | prtvtbfi==4 | prtvtbfi==5 | prtvtbfi==6|(prtvtbfi>=13& prtvtbfi<=15) | prtvtbfi==.) /*2010*/
keep if (prtvtcfi<=5 | (prtvtcfi>=12 & prtvtcfi<=14) | prtvtcfi==.) /*2012-2014*/
keep if (prtvtdfi<=5 | (prtvtdfi>=10 & prtvtdfi<=12) | prtvtdfi==.) /*2016-2018*/
keep if (prtvtefi<=7 | (prtvtefi>=16 & prtvtefi<=18) | prtvtefi==.) /*2020*/

*France*
keep if (prtvtfr==2 |(prtvtfr<=14&prtvtfr>=8) | prtvtfr==.) /*2002-2004*/
keep if (prtvtafr==2 |(prtvtafr<=14&prtvtafr>=8) | prtvtafr==.) /*2006*/
keep if ((prtvtbfr<=12&prtvtbfr>=5)| prtvtbfr==.) /*2008-2010*/
keep if ((prtvtcfr<=3&prtvtcfr>=1)| prtvtcfr==6 | prtvtcfr==7 |(prtvtcfr<=12&prtvtcfr>=9) | prtvtcfr==.) /*2012-2016*/
keep if ((prtvtdfr<=11&prtvtdfr>=3)| prtvtdfr==1| prtvtdfr==7 |(prtvtdfr<=12&prtvtdfr>=9) | prtvtdfr==.) /*2018*/
keep if ((prtvtefr<=11&prtvtefr>=3)| prtvtefr==1 | prtvtefr==.) /*2020*/

*UK*
keep if (prtvtgb<=5 | (prtvtgb<=14&prtvtgb>=11)  | prtvtgb==.)  /*ess 1,2,4-6*/
keep if (prtvtagb<=5 | (prtvtagb<=14&prtvtagb>=11) | prtvtagb==.)/*ess3*/
keep if (prtvtbgb<=5 | prtvtbgb==7 | (prtvtbgb<=12&prtvtbgb>=9) |prtvtbgb==.) /*2014-2016*/
keep if (prtvtcgb<=4 | prtvtcgb==10| prtvtcgb==11|prtvtcgb==.) /*2018*/
keep if (prtvtdgb<=4 |prtvtdgb==.) /*2020*/

*Greece*
keep if (prtvtgr<=4  | prtvtgr==.)  /*2002*/
keep if (prtvtagr<=4 | prtvtagr==.) /*2004*/
keep if (prtvtbgr<=5 | prtvtbgr==.) /*2008*/
keep if (prtvtcgr<=5 | prtvtcgr==.) /*2010*/
keep if (prtvtdgr<=6 | prtvtdgr==.) /*2020*/

*Ireland*
keep if (prtvtie<=7   | prtvtie==.) /*ess1-4*/
keep if (prtvtaie<=2  | prtvtaie>=4 & prtvtaie<=8 | prtvtaie==.) /*ess5-7*/
keep if (prtvtbie<=8 | prtvtbie==.) /*ess8*/
keep if (prtvtcie<=8 | prtvtcie==.) /*ess9*/
keep if (prtvtdie<=8 | prtvtdie==.) /*ess10*/

*Iceland*
keep if (prtvtis==1 | prtvtis==2 | prtvtis==4 | prtvtis==5 | prtvtis==7  | prtvtis==.) /*2004*/
keep if (prtvtais==1 | prtvtais==3 | prtvtais==4 | prtvtais==6| prtvtais==.) /*2012*/
keep if (prtvtbis<=3 | prtvtbis==8 | (prtvtbis<=12&prtvtbis>=10)| prtvtbis==.) /*2016*/
keep if (prtvtcis<=4 | prtvtcis==13 | (prtvtcis<=8&prtvtcis>=6)| prtvtcis==.) /*2018*/
keep if (prtvtdis<=11& prtvtdis>=4)| prtvtdis==. /*2020*/

*Italy*
keep if (prtvtit<=12  | prtvtit==.) /*2002*/
*keep if (prtvtait<=12 | prtvtait==.) /*2004, no observations*/
keep if (prtvtbit==1| prtvtbit==2 | (prtvtbit<=6&prtvtbit>=4) | (prtvtbit<=10&prtvtbit>=8 | prtvtbit==.))   /*2012, 2016*/
keep if ((prtvtcit==1| prtvtcit==2 ) | (prtvtcit<=10&prtvtcit>=7) | prtvtcit==.)   /*2018*/
keep if ((prtvtdit==14) |(prtvtdit<=7&prtvtdit>=1) | prtvtdit==.)   /*2020*/

*Netherlands*
keep if (prtvtnl<=9  | prtvtnl==. )  /*2002*/
keep if (prtvtanl<=8 |  prtvtanl==10 | prtvtanl==.) /*2004*/
keep if (prtvtbnl<=8 |  prtvtbnl==10 | prtvtbnl==.) /*2006*/
keep if (prtvtcnl<=3 | (prtvtcnl<=8&prtvtcnl>=5) | prtvtcnl==10 | prtvtcnl==.) /*2008*/
keep if (prtvtdnl<=3  | (prtvtdnl<=8&prtvtdnl>=5) |prtvtdnl==10 | prtvtdnl==.) /*2010*/
keep if (prtvtenl<=8  |  prtvtenl==10 | prtvtenl==12 | prtvten==.) /*2012*/
keep if (prtvtfnl<=8 | prtvtfnl==10| prtvtfnl==12 | prtvtfnl==.) /*2014-2016*/
keep if (prtvtgnl<=13 | prtvtgnl==.) /*2018*/
keep if (prtvthnl<=13 | prtvthnl==.) /*2020*/

*Norway*
keep if ((prtvtno<=8&prtvtno>=2)| prtvtno==.)    /*2002-2008*/
keep if ((prtvtano<=8&prtvtano>=2)| prtvtano==.) /*2010-2012*/
keep if ((prtvtbno<=8&prtvtbno>=2)| prtvtbno==.) /*2014-2020*/

*Portugal*
keep if (prtvtpt==1 | prtvtpt==2 | prtvtpt==5 | prtvtpt==10 | prtvtpt==11 | prtvtpt==.) /*2002-2004*/
keep if (prtvtapt==1 | prtvtapt==2 | prtvtapt==3 | prtvtapt==10 | prtvtapt==11 ///
		 | prtvtapt==.) /*2006-2008*/
keep if (prtvtbpt==1 | prtvtbpt==2 | prtvtbpt==3 | prtvtbpt==10 | prtvtbpt==11 ///
		 | prtvtbpt==.)/*2010-2014*/
keep if (prtvtcpt==2 | prtvtcpt==3 | prtvtcpt==13 | prtvtcpt==15| prtvtcpt==16  ///
		 | prtvtcpt==.) /*2016-2018*/
keep if (prtvtdpt==2 | prtvtdpt==3 | prtvtdpt==4 | prtvtdpt==5| prtvtdpt==7 | prtvtdpt==12| prtvtdpt==16 | prtvtdpt==18 ///
		 | prtvtdpt==.) /*2020*/

*Sweden*
keep if (prtvtse<=7  | prtvtse==.) /*2002-2008*/
keep if (prtvtase<=7 | prtvtase==10 | prtvtase==.) /*2010*/
keep if (prtvtbse<=7 | prtvtbse==10 | prtvtbse==.) /*2012-2016*/
keep if (prtvtcse<=7 | prtvtcse==9 | prtvtcse==.) /*2018*/
keep if (prtvtdse<=9 | prtvtdse==.) /*2020*/

*Luxemburg*
keep if (prtvtlu<=6|prtvtlu==.) /*2002-2004*/

/* 2. Define party families */
/*key for party coding, 
tens digit of party families is as the following:
   Communist	   1
   Left			   2
   Green		   3
   Liberal		   4
   Religious/CD	   5
   Aggrarian	   6
   Conservative	   7
   Radical Right   8
   Ethnic/Regional 9  
*/
/*Four sources of party family*/
gen prtyfam_lmn=.
gen prtyfam_glm=.
gen prtyfam_gn=.
gen prtyfam_parlgov=.
gen prtyfam_ours=.

**Austria**
replace prtyfam_lmn=21 if prtvtat==1 /*spo*/
replace prtyfam_lmn=52 if prtvtat==2 /*ovp*/
replace prtyfam_lmn=82 if prtvtat==3 /*fpo*/
replace prtyfam_lmn=31 if prtvtat==4 /*grn*/
replace prtyfam_lmn=21 if prtvtaat==1
replace prtyfam_lmn=52 if prtvtaat==2
replace prtyfam_lmn=82 if prtvtaat==3
replace prtyfam_lmn=86 if prtvtaat==4
replace prtyfam_lmn=31 if prtvtaat==5 
replace prtyfam_lmn=21 if prtvtbat==1 
replace prtyfam_lmn=52 if prtvtbat==2 
replace prtyfam_lmn=82 if prtvtbat==3 
replace prtyfam_lmn=86 if prtvtbat==4 
replace prtyfam_lmn=31 if prtvtbat==5 
replace prtyfam_lmn=41 if prtvtbat==7 
replace prtyfam_ours=41 if prtvtbat==9
replace prtyfam_lmn=21 if prtvtcat==1 
replace prtyfam_lmn=52 if prtvtcat==2 
replace prtyfam_lmn=82 if prtvtcat==3 
replace prtyfam_lmn=31 if prtvtcat==5 
replace prtyfam_lmn=41 if prtvtcat==7 

**Belguim**
replace prtyfam_lmn=51 if prtvtbe==2 /*cvp*/
replace prtyfam_lmn=21 if prtvtbe==3 /*sp*/
replace prtyfam_lmn=41 if prtvtbe==5 /*vld*/
replace prtyfam_lmn=91 if prtvtbe==6 /*vu-id*/
replace prtyfam_lmn=81 if prtvtbe==8 /*vlaams blok*/
replace prtyfam_lmn=31 if prtvtbe==11 /*ecolo*/
replace prtyfam_lmn=51 if prtvtbe==12 /*psc*/
replace prtyfam_lmn=41 if prtvtbe==13
replace prtyfam_lmn=21 if prtvtbe==14 /*ps*/
replace prtyfam_lmn=51 if prtvtabe==2 /*CD&V*/
replace prtyfam_lmn=91 if prtvtabe==3 /*N-VA*/
replace prtyfam_lmn=21 if prtvtabe==5/*SP.A-Spirit */
replace prtyfam_lmn=82 if prtvtabe==7 /*Vlaams Blok*/
replace prtyfam_lmn=41 if prtvtabe==8
replace prtyfam_lmn=51 if prtvtabe==9
replace prtyfam_lmn=31 if prtvtabe==10
replace prtyfam_lmn=81 if prtvtabe==11 /*Front National */
replace prtyfam_lmn=41 if prtvtabe==12
replace prtyfam_lmn=21 if prtvtabe==13 /*ps*/
replace prtyfam_lmn=31 if prtvtbbe==1
replace prtyfam_lmn=51 if prtvtbbe==2
replace prtyfam_lmn=41 if prtvtbbe==4
replace prtyfam_lmn=21 if prtvtbbe==5 /*SP.A-Spirit */
replace prtyfam_lmn=81 if prtvtbbe==7
replace prtyfam_lmn=41 if prtvtbbe==8
replace prtyfam_lmn=51 if prtvtbbe==9
replace prtyfam_lmn=31 if prtvtbbe==10
replace prtyfam_lmn=81 if prtvtbbe==11
replace prtyfam_lmn=41 if prtvtbbe==12
replace prtyfam_lmn=21 if prtvtbbe==13/*ps*/
replace prtyfam_lmn=31 if prtvtcbe==1
replace prtyfam_lmn=51 if prtvtcbe==2
replace prtyfam_lmn=91 if prtvtcbe==3 /*N-VA*/
replace prtyfam_lmn=41 if prtvtcbe==4
replace prtyfam_lmn=21 if prtvtcbe==5
replace prtyfam_lmn=41 if prtvtcbe==8
replace prtyfam_lmn=51 if prtvtcbe==9
replace prtyfam_lmn=31 if prtvtcbe==10
replace prtyfam_lmn=81 if prtvtcbe==11
replace prtyfam_lmn=41 if prtvtcbe==12
replace prtyfam_lmn=21 if prtvtcbe==13/*ps*/
replace prtyfam_lmn=82 if prtvtcbe==15
replace prtyfam_lmn=31 if prtvtdbe==1 /*Groen!*/
replace prtyfam_lmn=51 if prtvtdbe==2 /*CD&V */
replace prtyfam_lmn=91 if prtvtdbe==3 /*N-VA*/
replace prtyfam_lmn=21 if prtvtdbe==5 /*SP.A*/
replace prtyfam_lmn=22 if prtvtdbe==6 /*PVDA*/
replace prtyfam_lmn=82 if prtvtdbe==7 /*Vlaams Blok*/
replace prtyfam_lmn=41 if prtvtdbe==8 /*open vld*/
replace prtyfam_lmn=51 if prtvtdbe==9 /*cdh*/
replace prtyfam_lmn=31 if prtvtdbe==10 /*ecolo*/
replace prtyfam_lmn=41 if prtvtdbe==12 /*mr*/
replace prtyfam_lmn=21 if prtvtdbe==13/*ps*/
replace prtyfam_lmn=82 if prtvtdbe==15
replace prtyfam_lmn=91 if prtvtdbe==16
replace prtyfam_lmn=31 if prtvtebe==1 /*Groen!*/
replace prtyfam_lmn=51 if prtvtebe==2 /*CD&V */
replace prtyfam_lmn=91 if prtvtebe==3 /*N-VA*/
replace prtyfam_lmn=21 if prtvtebe==4 /*SP.A*/
replace prtyfam_lmn=22 if prtvtebe==5 /*PVDA*/
replace prtyfam_lmn=82 if prtvtebe==6 /*Vlaams Belang*/
replace prtyfam_lmn=41 if prtvtebe==7 /*open vld*/
replace prtyfam_lmn=51 if prtvtebe==8 /*cdh*/
replace prtyfam_lmn=31 if prtvtebe==9 /*ecolo*/
replace prtyfam_lmn=41 if prtvtebe==10 /*mr*/
replace prtyfam_lmn=21 if prtvtebe==11/*ps*/

**Denmark**
replace prtyfam_lmn=21 if prtvtdk==1/*Socialdemokratiet*/
replace prtyfam_lmn=41 if prtvtdk==2
replace prtyfam_lmn=71 if prtvtdk==3
replace prtyfam_lmn=22 if prtvtdk==5/*Socialistisk Folkeparti, clasified as radical left in ches */
replace prtyfam_lmn=86 if prtvtdk==6
replace prtyfam_lmn=51 if prtvtdk==7
replace prtyfam_lmn=41 if prtvtdk==8
replace prtyfam_ours=11 if prtvtdk==10
replace prtyfam_lmn=21 if prtvtadk==1
replace prtyfam_lmn=41 if prtvtadk==2
replace prtyfam_lmn=71 if prtvtadk==3
replace prtyfam_lmn=22 if prtvtadk==5
replace prtyfam_lmn=86 if prtvtadk==6
replace prtyfam_lmn=41 if prtvtadk==8
replace prtyfam_ours=11 if prtvtadk==10
replace prtyfam_lmn=21 if prtvtbdk==1
replace prtyfam_lmn=41 if prtvtbdk==2
replace prtyfam_lmn=71 if prtvtbdk==3
replace prtyfam_lmn=22 if prtvtbdk==4
replace prtyfam_lmn=86 if prtvtbdk==5
replace prtyfam_lmn=41 if prtvtbdk==7
replace prtyfam_lmn=41 if prtvtbdk==8
replace prtyfam_lmn=11 if prtvtbdk==9
replace prtyfam_lmn=21 if prtvtcdk==1
replace prtyfam_lmn=41 if prtvtcdk==2
replace prtyfam_lmn=71 if prtvtcdk==3
replace prtyfam_lmn=22 if prtvtcdk==4
replace prtyfam_lmn=86 if prtvtcdk==5
replace prtyfam_lmn=41 if prtvtcdk==7
replace prtyfam_lmn=41 if prtvtcdk==8
replace prtyfam_lmn=11 if prtvtcdk==9
replace prtyfam_lmn=21 if prtvtddk==1 /*l:sd*/
replace prtyfam_lmn=41 if prtvtddk==2
replace prtyfam_lmn=71 if prtvtddk==3
replace prtyfam_lmn=22 if prtvtddk==4 /*rl:sf*/
replace prtyfam_lmn=86 if prtvtddk==5 /*rr:df*/
replace prtyfam_lmn=41 if prtvtddk==7
replace prtyfam_lmn=41 if prtvtddk==8
replace prtyfam_lmn=31 if prtvtddk==9 /*grn:Alternative*/

**Finland**
replace prtyfam_lmn=71 if prtvtfi==1
replace prtyfam_lmn=91 if prtvtfi==2
replace prtyfam_lmn=61 if prtvtfi==4
replace prtyfam_lmn=86 if prtvtfi==5
replace prtyfam_lmn=51 if prtvtfi==6
replace prtyfam_lmn=31 if prtvtfi==8
replace prtyfam_lmn=21 if prtvtfi==9/*Finnish Social Democratic Party*/
replace prtyfam_lmn=11 if prtvtfi==10
replace prtyfam_lmn=71 if prtvtafi==1
replace prtyfam_lmn=91 if prtvtafi==2
replace prtyfam_lmn=61 if prtvtafi==4
replace prtyfam_lmn=86 if prtvtafi==5
replace prtyfam_lmn=51 if prtvtafi==6
replace prtyfam_lmn=31 if prtvtafi==7
replace prtyfam_lmn=21 if prtvtafi==8
replace prtyfam_lmn=11 if prtvtafi==9
replace prtyfam_lmn=71 if prtvtbfi==1
replace prtyfam_lmn=91 if prtvtbfi==2
replace prtyfam_lmn=61 if prtvtbfi==4
replace prtyfam_lmn=86 if prtvtbfi==5
replace prtyfam_lmn=51 if prtvtbfi==6
replace prtyfam_lmn=31 if prtvtbfi==13
replace prtyfam_lmn=21 if prtvtbfi==14/*Finnish Social Democratic Party*/
replace prtyfam_lmn=11 if prtvtbfi==15
replace prtyfam_lmn=71 if prtvtcfi==1
replace prtyfam_lmn=91 if prtvtcfi==2
replace prtyfam_lmn=61 if prtvtcfi==3
replace prtyfam_lmn=86 if prtvtcfi==4
replace prtyfam_ours=51 if prtvtcfi==5
replace prtyfam_lmn=31 if prtvtcfi==12
replace prtyfam_lmn=21 if prtvtcfi==13/*Finnish Social Democratic Party*/
replace prtyfam_lmn=11 if prtvtcfi==14
replace prtyfam_lmn=71 if prtvtdfi==1
replace prtyfam_lmn=91 if prtvtdfi==2
replace prtyfam_lmn=61 if prtvtdfi==3
replace prtyfam_lmn=86 if prtvtdfi==4
replace prtyfam_lmn=51 if prtvtdfi==5
replace prtyfam_ours=31 if prtvtdfi==10
replace prtyfam_ours=21 if prtvtdfi==11/*Finnish Social Democratic Party*/
replace prtyfam_lmn=11 if prtvtdfi==12
replace prtyfam_lmn=71 if prtvtefi==1
replace prtyfam_lmn=91 if prtvtefi==2
replace prtyfam_lmn=61 if prtvtefi==3
replace prtyfam_lmn=86 if prtvtefi==5 /*true finns*/
replace prtyfam_lmn=51 if prtvtefi==7
replace prtyfam_ours=31 if prtvtefi==16
replace prtyfam_ours=21 if prtvtefi==17/*Finnish Social Democratic Party*/
replace prtyfam_lmn=11 if prtvtefi==18

**Germany**
replace prtyfam_lmn=21 if prtvde2==1 /*spd*/
replace prtyfam_lmn=51 if prtvde2==2 /*cdu*/
replace prtyfam_lmn=31 if prtvde2==3 /*grn*/
replace prtyfam_lmn=41 if prtvde2==4 /*fdp*/
replace prtyfam_lmn=11 if prtvde2==5 /*pds*/
replace prtyfam_lmn=21 if prtvade2==1
replace prtyfam_lmn=51 if prtvade2==2
replace prtyfam_lmn=31 if prtvade2==3
replace prtyfam_lmn=41 if prtvade2==4
replace prtyfam_lmn=11 if prtvade2==5
replace prtyfam_lmn=21 if prtvbde2==1
replace prtyfam_lmn=51 if prtvbde2==2
replace prtyfam_lmn=31 if prtvbde2==3
replace prtyfam_lmn=41 if prtvbde2==4
replace prtyfam_lmn=11 if prtvbde2==5
replace prtyfam_lmn=21 if prtvcde2==1
replace prtyfam_lmn=51 if prtvcde2==2
replace prtyfam_lmn=31 if prtvcde2==3
replace prtyfam_lmn=41 if prtvcde2==4
replace prtyfam_lmn=11 if prtvcde2==5
replace prtyfam_lmn=21 if prtvdde2==1
replace prtyfam_lmn=51 if prtvdde2==2
replace prtyfam_lmn=31 if prtvdde2==3
replace prtyfam_lmn=41 if prtvdde2==4
replace prtyfam_lmn=11 if prtvdde2==5
replace prtyfam_lmn=51 if prtvede2==1
replace prtyfam_lmn=21 if prtvede2==2
replace prtyfam_lmn=11 if prtvede2==3
replace prtyfam_lmn=31 if prtvede2==4
replace prtyfam_lmn=51 if prtvfde2==1
replace prtyfam_lmn=21 if prtvfde2==2
replace prtyfam_lmn=11 if prtvfde2==3
replace prtyfam_lmn=41 if prtvfde2==4
replace prtyfam_lmn=11 if prtvfde2==5
replace prtyfam_lmn=86 if prtvfde2==6

**Greece** 
replace prtyfam_lmn=21 if prtvtgr==1/*pasok*/
replace prtyfam_lmn=71 if prtvtgr==2
replace prtyfam_lmn=11 if prtvtgr==3
replace prtyfam_lmn=11 if prtvtgr==4
replace prtyfam_lmn=21 if prtvtagr==1
replace prtyfam_lmn=71 if prtvtagr==2
replace prtyfam_lmn=11 if prtvtagr==3
replace prtyfam_lmn=11 if prtvtagr==4
replace prtyfam_lmn=21 if prtvtbgr==1
replace prtyfam_lmn=71 if prtvtbgr==2
replace prtyfam_lmn=11 if prtvtbgr==3
replace prtyfam_lmn=11 if prtvtbgr==4
replace prtyfam_lmn=81 if prtvtbgr==5
replace prtyfam_lmn=21 if prtvtcgr==1
replace prtyfam_lmn=71 if prtvtcgr==2
replace prtyfam_lmn=11 if prtvtcgr==3
replace prtyfam_lmn=81 if prtvtcgr==4
replace prtyfam_lmn=11 if prtvtcgr==5
replace prtyfam_lmn=71 if prtvtdgr==1 /*nd**/
replace prtyfam_lmn=11 if prtvtdgr==2 /*syriza*/
replace prtyfam_lmn=21 if prtvtdgr==3 /*pasok*/
replace prtyfam_lmn=11 if prtvtdgr==4 /*kke*/
replace prtyfam_lmn=81 if prtvtdgr==5 /*el*/
replace prtyfam_lmn=11 if prtvtdgr==6 /*mr25*/

**Iceland**
replace prtyfam_lmn=86 if prtvtis==1
replace prtyfam_lmn=81 if prtvtis==2
replace prtyfam_lmn=21 if prtvtis==4/*Social Democratic Alliance*/
replace prtyfam_lmn=71 if prtvtis==5
replace prtyfam_lmn=11 if prtvtis==7
replace prtyfam_lmn=21 if prtvtais==1/*Social Democratic Alliance*/
replace prtyfam_lmn=71 if prtvtais==3
replace prtyfam_lmn=11 if prtvtais==4
replace prtyfam_lmn=41 if prtvtbis==1
replace prtyfam_lmn=86 if prtvtbis==2
replace prtyfam_lmn=71 if prtvtbis==3
replace prtyfam_lmn=21 if prtvtbis==8
replace prtyfam_lmn=11 if prtvtbis==10
replace prtyfam_lmn=41 if prtvtbis==11
replace prtyfam_ours=41 if prtvtbis==12
replace prtyfam_lmn=71 if prtvtcis==1
replace prtyfam_lmn=86 if prtvtcis==2
replace prtyfam_lmn=11 if prtvtcis==3
replace prtyfam_lmn=21 if prtvtcis==4
replace prtyfam_lmn=41 if prtvtcis==6
replace prtyfam_lmn=41 if prtvtcis==7
replace prtyfam_ours=61 if prtvtcis==8
replace prtyfam_ours=81 if prtvtcis==13 /*peoples party - claisfied as prrps by the PopuList*/
replace prtyfam_lmn=81 if prtvtdis==4 /*peoples party*/
replace prtyfam_lmn=86 if prtvtdis==5 /*progress party*/
replace prtyfam_lmn=61 if prtvtdis==6
replace prtyfam_lmn=41 if prtvtdis==7
replace prtyfam_lmn=21 if prtvtdis==8
replace prtyfam_lmn=71 if prtvtdis==9
replace prtyfam_ours=41 if prtvtdis==10
replace prtyfam_ours=11 if prtvtdis==11 

**Ireland**
replace prtyfam_lmn=41     if prtvtie==1/* Fianna Fáil */
replace prtyfam_lmn=51     if prtvtie==2
replace prtyfam_lmn=21     if prtvtie==3/*Labour*/
replace prtyfam_lmn=91     if prtvtie==4
replace prtyfam_lmn=31     if prtvtie==5
replace prtyfam_lmn=91     if prtvtie==6
replace prtyfam_lmn=41     if prtvtaie==1
replace prtyfam_lmn=51     if prtvtaie==2
replace prtyfam_lmn=21     if prtvtaie==5
replace prtyfam_ours=22    if prtvtaie==6 /*people before profit*/
replace prtyfam_lmn=91     if prtvtaie==7
replace prtyfam_parlgov=12 if prtvtaie==8
*replace prtyfam_ours=12    if prtvtaie==9
replace prtyfam_ours=22    if prtvtbie==1 /*people before profit*/
replace prtyfam_lmn=41     if prtvtbie==2
replace prtyfam_lmn=51     if prtvtbie==3
replace prtyfam_ours=31    if prtvtbie==4
replace prtyfam_lmn=31     if prtvtbie==5
replace prtyfam_ours=21    if prtvtbie==6 /*labour*/
replace prtyfam_lmn=91     if prtvtbie==7
replace prtyfam_ours=21    if prtvtbie==8 /*social democrats*/
replace prtyfam_ours=22    if prtvtcie==1 /*people before profit*/
replace prtyfam_lmn=41     if prtvtcie==2
replace prtyfam_lmn=51     if prtvtcie==3
replace prtyfam_ours=31    if prtvtcie==4
replace prtyfam_lmn=31     if prtvtcie==5
replace prtyfam_ours=21    if prtvtcie==6 /*labour*/
replace prtyfam_lmn=91     if prtvtcie==7
replace prtyfam_ours=21    if prtvtcie==8 /*social democrats*/
replace prtyfam_ours=41    if prtvtdie==1 
replace prtyfam_lmn=51     if prtvtdie==2
replace prtyfam_lmn=21     if prtvtdie==3 /*labour*/
replace prtyfam_ours=91    if prtvtdie==4
replace prtyfam_lmn=31     if prtvtdie==5
replace prtyfam_ours=31    if prtvtdie==6 
replace prtyfam_lmn=21     if prtvtdie==7
replace prtyfam_ours=22    if prtvtdie==8 /*social democrats*/

**Italy**
replace prtyfam_parlgov=21 if prtvtit==1/*democratici di Sinistra*/
replace prtyfam_parlgov=41 if prtvtit==2
replace prtyfam_lmn=11     if prtvtit==3
replace prtyfam_parlgov=31 if prtvtit==4
replace prtyfam_lmn=11     if prtvtit==7
replace prtyfam_lmn=71     if prtvtit==8
replace prtyfam_lmn=81     if prtvtit==9
replace prtyfam_lmn=52     if prtvtit==10
replace prtyfam_glm=83     if prtvtit==11
replace prtyfam_parlgov=21 if prtvtit==12 /*Nuovo PSI */
replace prtyfam_parlgov=21 if prtvtait==1
replace prtyfam_parlgov=41 if prtvtait==2
replace prtyfam_lmn=11     if prtvtait==3
replace prtyfam_parlgov=31 if prtvtait==4
replace prtyfam_lmn=92     if prtvtait==6
replace prtyfam_lmn=11     if prtvtait==7
replace prtyfam_lmn=71     if prtvtait==8
replace prtyfam_lmn=81     if prtvtait==9
replace prtyfam_lmn=52     if prtvtait==10
replace prtyfam_glm=83     if prtvtait==11
replace prtyfam_parlgov=21 if prtvtait==12
replace prtyfam_parlgov=21 if prtvtbit==1
replace prtyfam_parlgov=12 if prtvtbit==2
*replace prtyfam_lmn=11     if prtvtbit==3
replace prtyfam_parlgov=31 if prtvtbit==4
replace prtyfam_parlgov=41 if prtvtbit==5
replace prtyfam_lmn=52     if prtvtbit==6
replace prtyfam_lmn=42     if prtvtbit==8
replace prtyfam_lmn=81     if prtvtbit==9
replace prtyfam_ours=71    if prtvtbit==10
replace prtyfam_parlgov=21 if prtvtcit==1 /*pd*/
replace prtyfam_parlgov=41 if prtvtcit==2
replace prtyfam_parlgov=31 if prtvtcit==7
replace prtyfam_parlgov=71 if prtvtcit==8 /* Forza Italia */
replace prtyfam_lmn=81     if prtvtcit==9 /*lega nord*/
replace prtyfam_ours=71    if prtvtcit==10
replace prtyfam_parlgov=21 if prtvtdit==1 /*pd*/
replace prtyfam_parlgov=41 if prtvtdit==2
replace prtyfam_parlgov=31 if prtvtdit==3
replace prtyfam_parlgov=71 if prtvtdit==4 /* Forza Italia */
replace prtyfam_lmn=71    if prtvtdit==5 /*Fratelli*/
replace prtyfam_ours=41    if prtvtdit==7
replace prtyfam_ours=91    if prtvtdit==14

**Netherlands**
replace prtyfam_lmn=51     if prtvtnl==1
replace prtyfam_lmn=21     if prtvtnl==2/*labour*/
replace prtyfam_lmn=41     if prtvtnl==3
replace prtyfam_parlgov=81 if prtvtnl==4
replace prtyfam_lmn=41     if prtvtnl==5
replace prtyfam_lmn=22     if prtvtnl==6 /*green left*/
replace prtyfam_parlgov=52 if prtvtnl==7
replace prtyfam_parlgov=81 if prtvtnl==8
replace prtyfam_ours=81    if prtvtnl==9
replace prtyfam_lmn=51     if prtvtanl==1
replace prtyfam_lmn=21     if prtvtanl==2 /*labour*/
replace prtyfam_lmn=41     if prtvtanl==3
replace prtyfam_parlgov=81 if prtvtanl==4
replace prtyfam_lmn=41     if prtvtanl==5
replace prtyfam_lmn=31     if prtvtanl==6
replace prtyfam_lmn=22     if prtvtanl==7 /*green left*/
replace prtyfam_parlgov=52 if prtvtanl==8
replace prtyfam_ours=51    if prtvtanl==10
replace prtyfam_lmn=51     if prtvtbnl==1
replace prtyfam_lmn=21     if prtvtbnl==2
replace prtyfam_lmn=41     if prtvtbnl==3
replace prtyfam_parlgov=81 if prtvtbnl==4
replace prtyfam_lmn=41     if prtvtbnl==5
replace prtyfam_lmn=31     if prtvtbnl==6
replace prtyfam_lmn=22     if prtvtbnl==7
replace prtyfam_parlgov=52 if prtvtbnl==8
replace prtyfam_ours=51    if prtvtbnl==10
replace prtyfam_lmn=51     if prtvtcnl==1
replace prtyfam_lmn=21     if prtvtcnl==2
replace prtyfam_lmn=41     if prtvtcnl==3
replace prtyfam_lmn=41     if prtvtcnl==5
replace prtyfam_lmn=31     if prtvtcnl==6
replace prtyfam_lmn=22     if prtvtcnl==7 /*socialist party*/
replace prtyfam_parlgov=52 if prtvtcnl==8
replace prtyfam_ours=51    if prtvtcnl==10
replace prtyfam_lmn=41     if prtvtdnl==1
replace prtyfam_lmn=21     if prtvtdnl==2
replace prtyfam_parlgov=86 if prtvtdnl==3
replace prtyfam_lmn=22     if prtvtdnl==5 /*socialist party*/
replace prtyfam_lmn=41     if prtvtdnl==6
replace prtyfam_lmn=31     if prtvtdnl==7
replace prtyfam_parlgov=52 if prtvtdnl==8
replace prtyfam_lmn=41     if prtvtenl==1
replace prtyfam_lmn=21     if prtvtenl==2
replace prtyfam_parlgov=86 if prtvtenl==3
replace prtyfam_lmn=51     if prtvtenl==4
replace prtyfam_lmn=22     if prtvtenl==5
replace prtyfam_lmn=41     if prtvtenl==6
replace prtyfam_lmn=31     if prtvtenl==7
replace prtyfam_parlgov=52 if prtvtenl==8
replace prtyfam_lmn=41     if prtvtfnl==1
replace prtyfam_lmn=21     if prtvtfnl==2
replace prtyfam_parlgov=86 if prtvtfnl==3
replace prtyfam_lmn=21     if prtvtfnl==4
replace prtyfam_lmn=51     if prtvtfnl==5
replace prtyfam_lmn=41     if prtvtfnl==6
replace prtyfam_lmn=52     if prtvtfnl==7
replace prtyfam_parlgov=31 if prtvtfnl==8
replace prtyfam_lmn=41     if prtvtgnl==1
replace prtyfam_lmn=21     if prtvtgnl==2 /*labour*/
replace prtyfam_parlgov=86 if prtvtgnl==3
replace prtyfam_lmn=21     if prtvtgnl==4
replace prtyfam_lmn=51     if prtvtgnl==5
replace prtyfam_lmn=41     if prtvtgnl==6
replace prtyfam_lmn=52     if prtvtgnl==7
replace prtyfam_parlgov=31 if prtvtgnl==8

replace prtyfam_lmn=41     if prtvthnl==1
replace prtyfam_lmn=21     if prtvthnl==2 /*labour*/
replace prtyfam_parlgov=86 if prtvthnl==3
replace prtyfam_lmn=21     if prtvthnl==4
replace prtyfam_lmn=51     if prtvthnl==5
replace prtyfam_lmn=41     if prtvthnl==6
replace prtyfam_lmn=52     if prtvthnl==7
replace prtyfam_parlgov=31 if prtvthnl==8

**Luxembourg**
replace prtyfam_lmn=51  if prtvtlu==1
replace prtyfam_lmn=21  if prtvtlu==2
replace prtyfam_lmn=41  if prtvtlu==3
replace prtyfam_ours=31 if prtvtlu==4
replace prtyfam_lmn=11  if prtvtlu==5
replace prtyfam_ours=71   if prtvtlu==6

**Norway**
*replace prtyfam_lmn=22  if prtvtno==1
replace prtyfam_lmn=21  if prtvtno==2
replace prtyfam_lmn=21  if prtvtno==3
replace prtyfam_lmn=41  if prtvtno==4
replace prtyfam_lmn=51  if prtvtno==5
replace prtyfam_glm=52  if prtvtno==5
replace prtyfam_lmn=61  if prtvtno==6
replace prtyfam_lmn=71  if prtvtno==7
replace prtyfam_lmn=86  if prtvtno==8
replace prtyfam_glm=82  if prtvtno==8
replace prtyfam_gn=83   if prtvtno==8
replace prtyfam_lmn=21  if prtvtano==2
replace prtyfam_lmn=21  if prtvtano==3
replace prtyfam_lmn=41  if prtvtano==4
replace prtyfam_lmn=51  if prtvtano==5
replace prtyfam_glm=52  if prtvtano==5
replace prtyfam_lmn=61  if prtvtano==6
replace prtyfam_lmn=71  if prtvtano==7
replace prtyfam_lmn=86  if prtvtano==8
replace prtyfam_glm=82  if prtvtano==8
replace prtyfam_gn=83   if prtvtano==8
replace prtyfam_lmn=21  if prtvtbno==2
replace prtyfam_lmn=21  if prtvtbno==3
replace prtyfam_lmn=41  if prtvtbno==4
replace prtyfam_lmn=51  if prtvtbno==5
replace prtyfam_glm=52  if prtvtbno==5
replace prtyfam_lmn=61  if prtvtbno==6
replace prtyfam_lmn=71  if prtvtbno==7
replace prtyfam_lmn=86  if prtvtbno==8
replace prtyfam_glm=82  if prtvtbno==8
replace prtyfam_gn=83   if prtvtbno==8

**UK**
replace prtyfam_lmn=71 	   if prtvtgb==1
replace prtyfam_lmn=21     if prtvtgb==2
replace prtyfam_glm=21     if prtvtgb==2
replace prtyfam_lmn=41     if prtvtgb==3
replace prtyfam_glm=41     if prtvtgb==3
replace prtyfam_lmn=91     if prtvtgb==4
replace prtyfam_lmn=91     if prtvtgb==5
replace prtyfam_parlgov=71 if prtvtgb==11
replace prtyfam_parlgov=71 if prtvtgb==12
replace prtyfam_parlgov=11 if prtvtgb==13
replace prtyfam_lmn=22     if prtvtgb==14/*Social Democratic and Labour Party (nir) */
replace prtyfam_glm=41     if prtvtgb==14
replace prtyfam_parlgov=22 if prtvtgb==14
replace prtyfam_lmn=71     if prtvtagb==1
replace prtyfam_lmn=21     if prtvtagb==2
replace prtyfam_glm=21     if prtvtagb==2
replace prtyfam_lmn=41     if prtvtagb==3
replace prtyfam_glm=41     if prtvtagb==3
replace prtyfam_lmn=91     if prtvtagb==4
replace prtyfam_lmn=91     if prtvtagb==5
replace prtyfam_parlgov=71 if prtvtagb==11
replace prtyfam_parlgov=71 if prtvtagb==12
replace prtyfam_parlgov=11 if prtvtagb==13
replace prtyfam_parlgov=22 if prtvtagb==14
replace prtyfam_lmn=71     if prtvtbgb==1
replace prtyfam_lmn=21     if prtvtbgb==2
replace prtyfam_glm=21     if prtvtbgb==2
replace prtyfam_lmn=41     if prtvtbgb==3
replace prtyfam_glm=41     if prtvtbgb==3
replace prtyfam_lmn=91     if prtvtbgb==4
replace prtyfam_lmn=91     if prtvtbgb==5
replace prtyfam_ours=81    if prtvtbgb==7
replace prtyfam_ours=71    if prtvtbgb==9
replace prtyfam_ours=71    if prtvtbgb==10
replace prtyfam_ours=11    if prtvtbgb==11
replace prtyfam_ours=22    if prtvtbgb==12 /*Social Democratic and Labour Party (nir) */
replace prtyfam_lmn=71     if prtvtcgb==1
replace prtyfam_lmn=21     if prtvtcgb==2
replace prtyfam_glm=21     if prtvtcgb==2
replace prtyfam_lmn=41     if prtvtcgb==3
replace prtyfam_glm=41     if prtvtcgb==3
replace prtyfam_lmn=91     if prtvtcgb==4
replace prtyfam_ours=71    if prtvtcgb==10
replace prtyfam_ours=11    if prtvtcgb==11
replace prtyfam_lmn=71     if prtvtdgb==1
replace prtyfam_lmn=21     if prtvtdgb==2
replace prtyfam_glm=21     if prtvtdgb==2
replace prtyfam_lmn=41     if prtvtdgb==3
replace prtyfam_glm=41     if prtvtdgb==3
replace prtyfam_lmn=91     if prtvtdgb==4

**Switzerland**
replace prtyfam_lmn=41 	   if prtvtch==1
replace prtyfam_parlgov=41 if prtvtch==1
replace prtyfam_lmn=51     if prtvtch==2
replace prtyfam_parlgov=52 if prtvtch==2
replace prtyfam_lmn=21     if prtvtch==3
replace prtyfam_parlgov=21 if prtvtch==3 /*social democrats*/
replace prtyfam_lmn=61     if prtvtch==4
replace prtyfam_parlgov=61 if prtvtch==4
replace prtyfam_ours=85    if prtvtch==4
replace prtyfam_lmn=61     if prtvtch==4
replace prtyfam_lmn=41     if prtvtch==5
replace prtyfam_parlgov=41 if prtvtch==5
replace prtyfam_parlgov=52 if prtvtch==7
replace prtyfam_parlgov=52 if prtvtch==8
replace prtyfam_parlgov=31 if prtvtch==10
replace prtyfam_ours=81     if prtvtch==11
replace prtyfam_parlgov=71 if prtvtch==12
replace prtyfam_parlgov=82 if prtvtch==15
replace prtyfam_ours=82    if prtvtch==15
replace prtyfam_lmn=41     if prtvtach==1
replace prtyfam_parlgov=41 if prtvtach==1
replace prtyfam_lmn=51     if prtvtach==2
replace prtyfam_parlgov=52 if prtvtach==2
replace prtyfam_lmn=21     if prtvtach==3 
replace prtyfam_parlgov=21 if prtvtach==3
replace prtyfam_lmn=61     if prtvtach==4
replace prtyfam_parlgov=61 if prtvtach==4
replace prtyfam_ours=85    if prtvtach==4
replace prtyfam_lmn=61     if prtvtach==4
replace prtyfam_lmn=41     if prtvtach==5
replace prtyfam_parlgov=41 if prtvtach==5
replace prtyfam_parlgov=52 if prtvtach==7
replace prtyfam_parlgov=52 if prtvtach==8
replace prtyfam_parlgov=31 if prtvtach==10
replace prtyfam_ours=81    if prtvtach==11
replace prtyfam_parlgov=71 if prtvtach==12
replace prtyfam_parlgov=82 if prtvtach==15
replace prtyfam_ours=82    if prtvtach==15
replace prtyfam_lmn=41     if prtvtbch==1
replace prtyfam_parlgov=41 if prtvtbch==1
replace prtyfam_lmn=51     if prtvtbch==2
replace prtyfam_parlgov=52 if prtvtbch==2
replace prtyfam_lmn=21     if prtvtbch==3
replace prtyfam_parlgov=21 if prtvtbch==3
replace prtyfam_lmn=61     if prtvtbch==4
replace prtyfam_parlgov=61 if prtvtbch==4
replace prtyfam_ours=85    if prtvtbch==4
replace prtyfam_lmn=61     if prtvtbch==4
replace prtyfam_lmn=41     if prtvtbch==5
replace prtyfam_parlgov=41 if prtvtbch==5
replace prtyfam_parlgov=52 if prtvtbch==6
replace prtyfam_parlgov=11 if prtvtbch==7
replace prtyfam_parlgov=31 if prtvtbch==8
replace prtyfam_parlgov=31 if prtvtbch==9
replace prtyfam_parlgov=71 if prtvtbch==11
replace prtyfam_parlgov=52 if prtvtbch==12
replace prtyfam_parlgov=82 if prtvtbch==13
replace prtyfam_ours=82    if prtvtbch==13
replace prtyfam_lmn=41     if prtvtcch==1
replace prtyfam_parlgov=41 if prtvtcch==1
replace prtyfam_lmn=51     if prtvtcch==2
replace prtyfam_parlgov=52 if prtvtcch==2
replace prtyfam_lmn=21     if prtvtcch==3
replace prtyfam_parlgov=21 if prtvtcch==3
replace prtyfam_lmn=61     if prtvtcch==4
replace prtyfam_parlgov=61 if prtvtcch==4
replace prtyfam_ours=85    if prtvtcch==4
replace prtyfam_lmn=41     if prtvtcch==5
replace prtyfam_parlgov=41 if prtvtcch==5
replace prtyfam_parlgov=52 if prtvtcch==6
replace prtyfam_parlgov=11 if prtvtcch==7
replace prtyfam_parlgov=31 if prtvtcch==8
replace prtyfam_parlgov=31 if prtvtcch==9
replace prtyfam_ours=81    if prtvtcch==10
replace prtyfam_parlgov=71 if prtvtcch==11
replace prtyfam_parlgov=52 if prtvtcch==12
replace prtyfam_parlgov=82 if prtvtcch==13
replace prtyfam_ours=82    if prtvtcch==13
replace prtyfam_lmn=61     if prtvtdch==1
replace prtyfam_parlgov=61 if prtvtdch==1
replace prtyfam_ours=85    if prtvtdch==1
replace prtyfam_parlgov=21 if prtvtdch==2
replace prtyfam_lmn=41     if prtvtdch==3
replace prtyfam_parlgov=41 if prtvtdch==3
replace prtyfam_lmn=51     if prtvtdch==4
replace prtyfam_parlgov=52 if prtvtdch==4
replace prtyfam_parlgov=31 if prtvtdch==5
replace prtyfam_parlgov=31 if prtvtcch==6
replace prtyfam_parlgov=71 if prtvtdch==7
replace prtyfam_parlgov=52 if prtvtdch==8
replace prtyfam_parlgov=82 if prtvtdch==12
replace prtyfam_ours=82    if prtvtdch==12
replace prtyfam_lmn=61     if prtvtech==1
replace prtyfam_parlgov=61 if prtvtech==1
replace prtyfam_ours=85    if prtvtech==1
replace prtyfam_parlgov=21 if prtvtech==2
replace prtyfam_lmn=41     if prtvtech==3
replace prtyfam_parlgov=41 if prtvtech==3
replace prtyfam_lmn=51     if prtvtech==4
replace prtyfam_parlgov=52 if prtvtech==4
replace prtyfam_parlgov=31 if prtvtech==5
replace prtyfam_parlgov=31 if prtvtech==6
replace prtyfam_parlgov=71 if prtvtech==7
replace prtyfam_parlgov=52 if prtvtech==8
replace prtyfam_ours=81    if prtvtech==10
replace prtyfam_parlgov=82 if prtvtech==12
replace prtyfam_ours=82    if prtvtech==12
replace prtyfam_lmn=61     if prtvtfch==1
replace prtyfam_parlgov=61 if prtvtfch==1
replace prtyfam_ours=85    if prtvtfch==1
replace prtyfam_parlgov=21 if prtvtfch==2
replace prtyfam_lmn=41     if prtvtfch==3
replace prtyfam_parlgov=41 if prtvtfch==3
replace prtyfam_lmn=51     if prtvtfch==4
replace prtyfam_parlgov=52 if prtvtfch==4
replace prtyfam_parlgov=31 if prtvtfch==5
replace prtyfam_parlgov=31 if prtvtfch==6
replace prtyfam_parlgov=71 if prtvtfch==7
replace prtyfam_parlgov=52 if prtvtfch==8
replace prtyfam_ours=81      if prtvtfch==10
replace prtyfam_ours=11      if prtvtfch==11
replace prtyfam_lmn=61     if prtvtgch==1
replace prtyfam_parlgov=61 if prtvtgch==1
replace prtyfam_ours=85    if prtvtgch==1 /*svp*/
replace prtyfam_parlgov=21 if prtvtgch==2
replace prtyfam_lmn=41     if prtvtgch==3
replace prtyfam_parlgov=41 if prtvtgch==3
replace prtyfam_lmn=51     if prtvtgch==4
replace prtyfam_parlgov=52 if prtvtgch==4
replace prtyfam_parlgov=31 if prtvtgch==5
replace prtyfam_parlgov=31 if prtvtgch==6
replace prtyfam_parlgov=71 if prtvtgch==7
replace prtyfam_parlgov=52 if prtvtgch==8
replace prtyfam_ours=81      if prtvtgch==10
replace prtyfam_lmn=61     if prtvthch==1
replace prtyfam_parlgov=61 if prtvthch==1
replace prtyfam_ours=85    if prtvthch==1 /*svp*/
replace prtyfam_parlgov=21 if prtvthch==2
replace prtyfam_lmn=41     if prtvthch==3
replace prtyfam_parlgov=41 if prtvthch==3
replace prtyfam_lmn=31     if prtvthch==4
replace prtyfam_parlgov=51 if prtvthch==5
replace prtyfam_parlgov=31 if prtvthch==6
replace prtyfam_parlgov=71 if prtvthch==7
replace prtyfam_parlgov=52 if prtvthch==8

**france**
replace prtyfam_ours=41     if prtvtfr==2
replace prtyfam_parlgov=71 if prtvtfr==8
replace prtyfam_lmn=11     if prtvtfr==9
replace prtyfam_lmn=21     if prtvtfr==10 /*ps*/
replace prtyfam_ours=71    if prtvtfr==11
replace prtyfam_lmn=71     if prtvtfr==12
replace prtyfam_lmn=71     if prtvtfr==13
replace prtyfam_lmn=31     if prtvtfr==14
replace prtyfam_lmn=41     if prtvtafr==2
replace prtyfam_parlgov=71 if prtvtafr==8
replace prtyfam_lmn=11 	   if prtvtafr==9
replace prtyfam_lmn=21     if prtvtafr==10
replace prtyfam_ours=71    if prtvtafr==11
replace prtyfam_lmn=71     if prtvtafr==12
replace prtyfam_lmn=71     if prtvtafr==13
replace prtyfam_lmn=31     if prtvtafr==14
replace prtyfam_ours=71    if prtvtbfr==5
replace prtyfam_parlgov=41 if prtvtbfr==6
replace prtyfam_lmn=11     if prtvtbfr==7 
replace prtyfam_lmn=21     if prtvtbfr==8/*ps*/
replace prtyfam_lmn=41     if prtvtbfr==9
replace prtyfam_parlgov=22 if prtvtbfr==9 /*PRG (Parti Radical de Gauche)*/
replace prtyfam_parlgov=41 if prtvtbfr==10
replace prtyfam_lmn=71     if prtvtbfr==11
replace prtyfam_lmn=31     if prtvtbfr==12
replace prtyfam_lmn=41 	   if prtvtcfr==1
replace prtyfam_parlgov=81 if prtvtcfr==2
replace prtyfam_ours=41    if prtvtcfr==3
replace prtyfam_ours=22    if prtvtcfr==6 /* FDG (Front de Gauche)*/
replace prtyfam_parlgov=22 if prtvtcfr==7 /*Parti Radical de Gauche */
replace prtyfam_lmn=21     if prtvtcfr==9 /*ps*/
replace prtyfam_lmn=71     if prtvtcfr==10
replace prtyfam_parlgov=41 if prtvtcfr==11
replace prtyfam_lmn=31     if prtvtcfr==12
replace prtyfam_lmn=11 	   if prtvtdfr==1
replace prtyfam_parlgov=11 if prtvtdfr==3
replace prtyfam_ours=22    if prtvtdfr==4 /*fi*/
replace prtyfam_parlgov=21 if prtvtdfr==5 /*ps*/
replace prtyfam_lmn=31     if prtvtdfr==6 /*eelv*/
replace prtyfam_lmn=41     if prtvtdfr==7 /*lrem*/
replace prtyfam_parlgov=41 if prtvtdfr==8 /*modem*/
replace prtyfam_lmn=71     if prtvtdfr==9 /*lr*/
replace prtyfam_lmn=81     if prtvtdfr==10 /*dlf*/
replace prtyfam_parlgov=81 if prtvtdfr==11 /*fn*/
replace prtyfam_lmn=11 	   if prtvtefr==1 /*lo*/
replace prtyfam_parlgov=11 if prtvtefr==3 /*pcf*/
replace prtyfam_ours=22    if prtvtefr==4 /*fi*/
replace prtyfam_parlgov=21 if prtvtefr==5 /*ps*/
replace prtyfam_lmn=31     if prtvtefr==6 /*eelv*/
replace prtyfam_lmn=41     if prtvtefr==7 /*lrem*/
replace prtyfam_parlgov=41 if prtvtefr==8 /*modem*/
replace prtyfam_lmn=71     if prtvtefr==9 /*lr*/
replace prtyfam_lmn=81     if prtvtefr==10 /*dlf*/
replace prtyfam_parlgov=81 if prtvtefr==11 /*fn*/

**portugal**
replace prtyfam_parlgov=11 if prtvtpt==1
replace prtyfam_lmn=52     if prtvtpt==2
replace prtyfam_lmn=11     if prtvtpt==5
replace prtyfam_lmn=21     if prtvtpt==10 /* PS - Partido Socialista */
replace prtyfam_lmn=41     if prtvtpt==11
replace prtyfam_parlgov=11 if prtvtapt==1
replace prtyfam_lmn=52     if prtvtapt==2
replace prtyfam_lmn=11     if prtvtapt==3
replace prtyfam_lmn=41     if prtvtapt==10
replace prtyfam_lmn=21     if prtvtapt==11
replace prtyfam_parlgov=11 if prtvtbpt==1
replace prtyfam_lmn=52     if prtvtbpt==2
replace prtyfam_parlgov=11 if prtvtbpt==3
replace prtyfam_lmn=41     if prtvtbpt==10
replace prtyfam_lmn=21     if prtvtbpt==11
replace prtyfam_parlgov=11 if prtvtcpt==2
replace prtyfam_lmn=11     if prtvtcpt==3
replace prtyfam_parlgov=21 if prtvtcpt==13
replace prtyfam_lmn=41     if prtvtcpt==16
replace prtyfam_parlgov=11 if prtvtdpt==2
replace prtyfam_lmn=41     if prtvtdpt==3
replace prtyfam_parlgov=81 if prtvtdpt==4 /*chega*/
replace prtyfam_lmn=11     if prtvtdpt==12
replace prtyfam_parlgov=21 if prtvtdpt==16 /*psd*/
replace prtyfam_lmn=21     if prtvtdpt==18 /*ps*/

*Sweden*
replace prtyfam_lmn=61  	if prtvtse==1
replace prtyfam_lmn=41  	if prtvtse==2
replace prtyfam_lmn=52  	if prtvtse==3
replace prtyfam_gn=51   	if prtvtse==3
replace prtyfam_lmn=31  	if prtvtse==4
replace prtyfam_lmn=71  	if prtvtse==5
replace prtyfam_lmn=21  	if prtvtse==6 /*Social Democrats*/
replace prtyfam_lmn=11  	if prtvtse==7
replace prtyfam_lmn=61  	if prtvtase==1
replace prtyfam_lmn=41  	if prtvtase==2
replace prtyfam_lmn=52  	if prtvtase==3
replace prtyfam_gn=51   	if prtvtase==3
replace prtyfam_lmn=31  	if prtvtase==4
replace prtyfam_lmn=71  	if prtvtase==5
replace prtyfam_lmn=21  	if prtvtase==6
replace prtyfam_lmn=11  	if prtvtase==7
replace prtyfam_ours=85 	if prtvtase==10
replace prtyfam_parlgov=83  if prtvtase==10

replace prtyfam_lmn=61      if prtvtbse==1
replace prtyfam_lmn=41      if prtvtbse==2
replace prtyfam_lmn=52      if prtvtbse==3
replace prtyfam_gn=51       if prtvtbse==3
replace prtyfam_lmn=31      if prtvtbse==4
replace prtyfam_lmn=71      if prtvtbse==5
replace prtyfam_lmn=21      if prtvtbse==6
replace prtyfam_lmn=11      if prtvtbse==7
replace prtyfam_ours=85     if prtvtbse==10
replace prtyfam_parlgov=83  if prtvtbse==10
replace prtyfam_lmn=61      if prtvtcse==1
replace prtyfam_lmn=41      if prtvtcse==2
replace prtyfam_lmn=52      if prtvtcse==3
replace prtyfam_gn=51       if prtvtcse==3
replace prtyfam_lmn=31      if prtvtcse==4
replace prtyfam_lmn=71      if prtvtcse==5
replace prtyfam_lmn=21      if prtvtcse==6
replace prtyfam_lmn=11      if prtvtcse==7
replace prtyfam_ours=85     if prtvtcse==9
replace prtyfam_parlgov=83  if prtvtcse==9
replace prtyfam_lmn=61      if prtvtdse==1
replace prtyfam_lmn=51      if prtvtdse==2
replace prtyfam_lmn=41      if prtvtdse==3
replace prtyfam_gn=42       if prtvtdse==3
replace prtyfam_lmn=31      if prtvtdse==4
replace prtyfam_lmn=71      if prtvtdse==5
replace prtyfam_lmn=21      if prtvtdse==6
replace prtyfam_lmn=81      if prtvtdse==7
replace prtyfam_ours=11     if prtvtdse==8

*Spain*
replace prtyfam_lmn=71  	if prtvtes==1
replace prtyfam_lmn=21  	if prtvtes==2 /*psoe*/
replace prtyfam_ours=12 	if prtvtes==3
replace prtyfam_lmn=91  	if prtvtes==4
replace prtyfam_ours=41 	if prtvtes==4
replace prtyfam_lmn=91  	if prtvtes==5
replace prtyfam_ours=41 	if prtvtes==5
replace prtyfam_parlgov=31  if prtvtes==6
replace prtyfam_ours=42 	if prtvtes==7
replace prtyfam_ours=42 	if prtvtes==8
replace prtyfam_lmn=91 		if prtvtes==9
replace prtyfam_lmn=91 		if prtvtes==10
replace prtyfam_ours=22 	if prtvtes==11 /* Partido Andalucista */
replace prtyfam_ours=91 	if prtvtes==12
replace prtyfam_lmn=71 		if prtvtaes==1
replace prtyfam_lmn=21 		if prtvtaes==2
replace prtyfam_ours=12 	if prtvtaes==3
replace prtyfam_lmn=91  	if prtvtaes==4
replace prtyfam_ours=41 	if prtvtaes==4
replace prtyfam_lmn=91 		if prtvtaes==5
replace prtyfam_ours=41 	if prtvtaes==5
replace prtyfam_ours=42 	if prtvtaes==7
replace prtyfam_ours=42 	if prtvtaes==8
replace prtyfam_lmn=91 		if prtvtaes==9
replace prtyfam_lmn=91 		if prtvtaes==10
replace prtyfam_ours=91 	if prtvtaes==12
replace prtyfam_ours=91 	if prtvtaes==13
replace prtyfam_lmn=71 		if prtvtbes==1
replace prtyfam_lmn=21 		if prtvtbes==2
replace prtyfam_ours=12 	if prtvtbes==3
replace prtyfam_lmn=91 		if prtvtbes==4
replace prtyfam_ours=41 	if prtvtbes==4
replace prtyfam_lmn=91 		if prtvtbes==5
replace prtyfam_ours=41 	if prtvtbes==5
replace prtyfam_ours=42 	if prtvtbes==6
replace prtyfam_lmn=91 		if prtvtbes==7
replace prtyfam_lmn=91 		if prtvtbes==8
replace prtyfam_ours=91 	if prtvtbes==9
replace prtyfam_parlgov=41  if prtvtbes==10
replace prtyfam_lmn=71 		if prtvtces==1
replace prtyfam_lmn=21 		if prtvtces==2
replace prtyfam_lmn=91 		if prtvtces==3
replace prtyfam_ours=12 	if prtvtces==4
replace prtyfam_ours=65 	if prtvtces==5 
replace prtyfam_parlgov=41  if prtvtces==6
replace prtyfam_lmn=42 		if prtvtces==7
replace prtyfam_lmn=91      if prtvtces==8
replace prtyfam_lmn=91 		if prtvtces==9
replace prtyfam_lmn=91 		if prtvtces==10
replace prtyfam_lmn=91 		if prtvtces==11
replace prtyfam_parlgov=71  if prtvtces==12
replace prtyfam_lmn=71 		if prtvtdes==1
replace prtyfam_lmn=21 		if prtvtdes==2
replace prtyfam_lmn=11 		if prtvtdes==3
replace prtyfam_ours=41 	if prtvtdes==5
replace prtyfam_ours=11 	if prtvtdes==7 
replace prtyfam_lmn=11 		if prtvtdes==8
replace prtyfam_lmn=91 		if prtvtdes==10
replace prtyfam_lmn=91 		if prtvtdes==11
replace prtyfam_ours=12 	if prtvtdes==14
replace prtyfam_lmn=71 		if prtvtees==1
replace prtyfam_lmn=21 		if prtvtees==2
replace prtyfam_lmn=11 		if prtvtees==3
replace prtyfam_ours=41 	if prtvtees==5
replace prtyfam_ours=91 	if prtvtees==10
 

/* Turning wide vote choice variables to long: 
   ESS dataset was organized such that every country (c)/ wave (j) had a vote choice 
   variable. These data look like a block Swiss cheese dataset, where for every such 
   variable there is an N(cj)-element column of vote-choice responses and missing entries 
   for the rest of the N observations in the dataset. Here, we generate a single 
   variable that "aggregates" across columns and collapses these cj columns into one */

egen votechoice=rowtotal(prtvtat prtvtaat prtvtbat prtvtbe prtvtabe prtvtbbe prtvtcbe /// 
	 prtvtch prtvtach prtvtbch prtvtcch prtvtdch prtvtech prtvtfch prtvde2 prtvade2 prtvbde2 prtvcde2 /// 
	 prtvdde2 prtvede2 prtvtdk prtvtadk prtvtbdk prtvtcdk prtvtes prtvtaes prtvtbes prtvtces prtvtdes ///
	 prtvtfi prtvtafi prtvtbfi prtvtcfi prtvtdfi prtvtfr prtvtafr prtvtbfr prtvtcfr prtvtgb /// 
	 prtvtagb prtvtbgb prtvtgr prtvtagr prtvtbgr prtvtcgr prtvtie prtvtaie prtvtbie prtvtis prtvtais ///
	 prtvtit prtvtait prtvtbit prtvtnl prtvtanl prtvtbnl prtvtcnl prtvtdnl prtvtenl prtvtfnl ///
	 prtvtbis prtvtno prtvtano prtvtbno prtvtpt prtvtapt prtvtbpt prtvtcpt prtvtse prtvtase prtvtbse prtvtlu prtvtcat prtvtdbe prtvtebe prtvtgch prtvthch prtvfde2 prtvtddk prtvtees prtvtfes prtvtefi prtvtdfr prtvtefr prtvtcgb prtvtdgb prtvtdgr prtvtcie prtvtdie prtvtcis prtvtdis prtvtcit prtvtdit prtvtgnl prtvthnl prtvtdpt prtvtdse) 

/* Party families: indicates if respondent voted for a party included in the 
   party family	*/
gen prtyfam_rr=.
gen prtyfam_left=.
gen prtyfam_left_wgreen=.
gen prtyfam_grn=.
gen prtyfam_cd=.
gen prtyfam_cons=.
gen prtyfam_radicalleft=.
gen prtyfam_lib=.
gen prtyfam_sd=.

replace prtyfam_rr = (prtyfam_lmn<=86&prtyfam_lmn>=81)|(prtyfam_glm<=86&prtyfam_glm>=81) | ///
	(prtyfam_gn<=86&prtyfam_gn>=81)|(prtyfam_ours<=86&prtyfam_ours>=81) |(prtyfam_parlgov<=86&prtyfam_parlgov>=81)
	
replace prtyfam_left = (prtyfam_lmn==22|prtyfam_lmn==21)|(prtyfam_glm==22|prtyfam_glm==21) | ///
	(prtyfam_ours==22|prtyfam_ours==21)|(prtyfam_parlgov==22|prtyfam_parlgov==21)
replace prtyfam_sd = (prtyfam_lmn==21)|(prtyfam_glm==21) | ///
	(prtyfam_ours==21)|(prtyfam_parlgov==21)
	
replace prtyfam_left_wgreen= (prtyfam_lmn==22|prtyfam_lmn==21|prtyfam_lmn==31) ///
    |(prtyfam_glm==22|prtyfam_glm==21|prtyfam_glm==31) | ///
	(prtyfam_ours==22|prtyfam_ours==21|prtyfam_ours==31) |(prtyfam_parlgov==22|prtyfam_parlgov==21|prtyfam_parlgov==31) 
	
replace prtyfam_cd = (prtyfam_lmn<=59&prtyfam_lmn>=50)|(prtyfam_glm<=59&prtyfam_glm>=50) | ///
	(prtyfam_gn<=59&prtyfam_gn>=50)|(prtyfam_ours<=59&prtyfam_ours>=50) |(prtyfam_parlgov<=59&prtyfam_parlgov>=50)
	
replace prtyfam_cons = (prtyfam_lmn<=79&prtyfam_lmn>=70)|(prtyfam_glm<=79&prtyfam_glm>=70) | ///
	(prtyfam_gn<=79&prtyfam_gn>=70)|(prtyfam_ours<=79&prtyfam_ours>=70)|(prtyfam_parlgov<=79&prtyfam_parlgov>=70)
	
replace prtyfam_radicalleft = (prtyfam_lmn==11|prtyfam_lmn==12)|(prtyfam_glm==11|prtyfam_glm==12) | ///
	(prtyfam_ours==11|prtyfam_ours==12) |(prtyfam_parlgov==11|prtyfam_parlgov==12) |(prtyfam_lmn==22)|(prtyfam_glm==22) | ///
	(prtyfam_ours==22)|(prtyfam_parlgov==22)
	
replace prtyfam_lib = (prtyfam_lmn==41|prtyfam_lmn==42)|(prtyfam_glm==41|prtyfam_glm==42) | ///
	(prtyfam_ours==41|prtyfam_ours==42) | (prtyfam_gn==41|prtyfam_gn==42) |(prtyfam_parlgov==41|prtyfam_parlgov==42)
	
replace prtyfam_grn= prtyfam_lmn==31 ///
    |prtyfam_glm==31 | ///
	prtyfam_ours==31 |prtyfam_parlgov==31

	
/*  Generate the gender specific vote share variabes for RR 
	Numerator:   number of M or F in country C, in round j, who voted for rr
	Denominator: number of M or F in country C, in round j (who voted, screening for turnout above)*/

by cntry essround gndr, sort: egen countgndrrr=count(gndr) if prtyfam_rr==1
by cntry essround gndr, sort: egen countgndrpf=count(gndr)
gen     vsfpfrr = .
replace vsfpfrr = countgndrrr/countgndrpf  if gndr==0
gen     vsmpfrr = .
replace vsmpfrr = countgndrrr/countgndrpf  if gndr==1

by cntry essround prtyfam_rr, sort: egen vsfpfrrunique=max(vsfpfrr)
by cntry essround prtyfam_rr, sort: egen vsmpfrrunique=max(vsmpfrr)

*   RR gender gap: VSM-VSF 
gen gendergappfrr=vsmpfrrunique-vsfpfrrunique

/* Generate the gender specific vote share variabe for Left 
   Numerator: number of M or F in country C, in round j, who voted for left 
   Denominator: number of M or F in country C, in round j (who voted, screening for turnout above)*/
by cntry essround gndr, sort: egen countgndrl=count(gndr) if prtyfam_left==1
gen     vsfpfl = .
replace vsfpfl = countgndrl/countgndrpf  if gndr==0
gen     vsmpfl = .
replace vsmpfl = countgndrl/countgndrpf  if gndr==1

by cntry essround prtyfam_left, sort: egen vsfpflunique=max(vsfpfl)
by cntry essround prtyfam_left, sort: egen vsmpflunique=max(vsmpfl)

* Left gender gap: VSM-VSF**
gen gendergappfl=vsmpflunique-vsfpflunique

/* Generate the gender specific vote share variabe for sd 
   Numerator: number of M or F in country C, in round j, who voted for sd 
   Denominator: number of M or F in country C, in round j (who voted, screening for turnout above)*/
by cntry essround gndr, sort: egen countgndrsd=count(gndr) if prtyfam_sd==1
gen     vsfpfsd = .
replace vsfpfsd = countgndrsd/countgndrpf  if gndr==0
gen     vsmpfsd = .
replace vsmpfsd = countgndrsd/countgndrpf  if gndr==1

by cntry essround prtyfam_sd, sort: egen vsfpfsdunique=max(vsfpfsd)
by cntry essround prtyfam_sd, sort: egen vsmpfsdunique=max(vsmpfsd)

* SD gender gap: VSM-VSF**
gen gendergappfsd=vsmpfsdunique-vsfpfsdunique

/* Generate the gender specific vote share variabe for Left WITH GREEN PARTY FAMILY 
   Numerator: number of M or F in country C, in round j, who voted for left+grn
   Denominator: number of M or F in country C, in round j (who voted, screening for turnout above)*/
by cntry essround gndr, sort: egen countgndrl_g=count(gndr) if prtyfam_left_wgreen==1
gen     vsfpfl_g = .
replace vsfpfl_g = countgndrl_g/countgndrpf  if gndr==0
gen     vsmpfl_g = .
replace vsmpfl_g = countgndrl_g/countgndrpf  if gndr==1

by cntry essround prtyfam_left_wgreen, sort: egen vsfpflunique_g=max(vsfpfl_g)
by cntry essround prtyfam_left_wgreen, sort: egen vsmpflunique_g=max(vsmpfl_g)

* Left gender gap WITH GREEN PARTY FAMILY: VSM-VSF**
gen gendergappfl_g=vsmpflunique_g-vsfpflunique_g

/* Generate the gender specific vote share variabe for GREEN PARTY FAMILY 
   Numerator: number of M or F in country C, in round j, who voted for grn 
   Denominator: number of M or F in country C, in round j (who voted, screening for turnout above)*/
by cntry essround gndr, sort: egen countgndr_g=count(gndr) if prtyfam_grn==1
gen     vsfpf_g = .
replace vsfpf_g = countgndr_g/countgndrpf  if gndr==0
gen     vsmpf_g = .
replace vsmpf_g = countgndr_g/countgndrpf  if gndr==1

by cntry essround prtyfam_grn, sort: egen vsfpfunique_g=max(vsfpf_g)
by cntry essround prtyfam_grn, sort: egen vsmpfunique_g=max(vsmpf_g)

* Left gender gap WITH GREEN PARTY FAMILY: VSM-VSF**
gen gendergappf_g=vsmpfunique_g-vsfpfunique_g

/*  Generate the gender specific vote share variabe for CD 
	Numerator: number of M or F in country C, in round j, who voted for CD
	Denominator: number of M or F in country C, in round j (who voted, screening for turnout above)*/

by cntry essround gndr, sort: egen countgndrcd=count(gndr) if prtyfam_cd==1
gen     vsfcd = .
replace vsfcd = countgndrcd/countgndrpf  if gndr==0
gen     vsmcd = .
replace vsmcd = countgndrcd/countgndrpf  if gndr==1

by cntry essround prtyfam_cd, sort: egen vsfcdunique=max(vsfcd)
by cntry essround prtyfam_cd, sort: egen vsmcdunique=max(vsmcd)

*   CD gender gap: VSM-VSF 
gen gendergapcd=vsmcdunique-vsfcdunique

/*  Generate the gender specific vote share variabe for conservative party family 
	Numerator: number of M or F in country C, in round j, who voted for consver.
	Denominator: number of M or F in country C, in round j (who voted, screening for turnout above)*/

by cntry essround gndr, sort: egen countgndrcons=count(gndr) if prtyfam_cons==1
gen     vsfcons = .
replace vsfcons = countgndrcons/countgndrpf  if gndr==0
gen     vsmcons = .
replace vsmcons = countgndrcons/countgndrpf  if gndr==1

by cntry essround prtyfam_cons, sort: egen vsfconsunique=max(vsfcons)
by cntry essround prtyfam_cons, sort: egen vsmconsunique=max(vsmcons)

*   Conservative gender gap: VSM-VSF 
gen gendergapcons=vsmconsunique-vsfconsunique

/*  Generate the gender specific vote share variabe for radical left party family 
	Numerator: number of M or F in country C, in round j, who voted for radical left.
	Denominator: number of M or F in country C, in round j (who voted, screening for turnout above)*/

by cntry essround gndr, sort: egen countgndrrleft=count(gndr) if prtyfam_radicalleft==1
gen     vsfrleft = .
replace vsfrleft = countgndrrleft/countgndrpf  if gndr==0
gen     vsmrleft = .
replace vsmrleft = countgndrrleft/countgndrpf  if gndr==1

by cntry essround prtyfam_radicalleft, sort: egen vsfrleftunique=max(vsfrleft)
by cntry essround prtyfam_radicalleft, sort: egen vsmrleftunique=max(vsmrleft)

*   radical left gender gap: VSM-VSF 
gen gendergaprleft=vsmrleftunique-vsfrleftunique

/*  Generate the gender specific vote share variabe for liberals party family 
	Numerator: number of M or F in country C, in round j, who voted for liberals.
	Denominator: number of M or F in country C, in round j (who voted, screening for turnout above)*/

by cntry essround gndr, sort: egen countgndrlib=count(gndr) if prtyfam_lib==1
gen     vsflib = .
replace vsflib = countgndrlib/countgndrpf  if gndr==0
gen     vsmlib = .
replace vsmlib = countgndrlib/countgndrpf  if gndr==1

by cntry essround prtyfam_lib, sort: egen vsflibunique=max(vsflib)
by cntry essround prtyfam_lib, sort: egen vsmlibunique=max(vsmlib)

*   liberals gender gap: VSM-VSF 
gen gendergaplib=vsmlibunique-vsflibunique

/* preparation for aggregate figures of the gender gaps*/
gen year_2dig = string(mod(year,100), "%02.0f")  
gen cntryear=cntry+year_2dig

* Unique gender gap variable for every year and country : sd
egen ggsdunique=tag(gendergappfsd cntryear)
by cntry essround, sort: egen ggsdunique1=max(gendergappfsd) if ggsdunique==1

* Unique gender gap variable for every year and country : RR
egen ggrrunique=tag(gendergappfrr cntryear)
by cntry essround, sort: gen ggrrunique1=sum(gendergappfrr) if ggrrunique==1

* Unique gender gap variable for every year and country : CD
egen ggcdunique=tag(gendergapcd cntryear)
by cntry essround, sort: gen ggcdunique1=sum(gendergapcd) if ggcdunique==1

* Unique gender gap variable for every year and country : Conservative
egen ggconsunique=tag(gendergapcons cntryear)
by cntry essround, sort: gen ggconsunique1=sum(gendergapcons) if ggconsunique==1

* Unique gender gap variable for every year and country: Radical Left
egen ggrlunique=tag(gendergaprleft cntryear)
by cntry essround, sort: gen ggrlunique1=sum(gendergaprleft) if ggrlunique==1

* Unique gender gap variable for every year and country: Liberals
egen gglibunique=tag(gendergaplib cntryear)
by cntry essround, sort: gen gglibunique1=sum(gendergaplib) if gglibunique==1

* Unique gender gap variable for every year and country : GREEN PARTY FAM
egen ggunique_g=tag(gendergappf_g cntryear)
by cntry essround, sort: gen ggunique1_g=sum(gendergappf_g) if ggunique_g==1

gen ggsdper = ggsdunique1*100

* cntryrr: captures countries that have RR in year j 
gen cntryrr=.
replace cntryrr=1 if essround==1 & (cntry=="AT"|cntry=="BE"|cntry=="CH"|cntry=="DK"|cntry=="FI"| ///
cntry=="FR"|cntry=="IT"|cntry=="NL"|cntry=="NO") 
replace cntryrr=1 if essround==2 & (cntry=="AT"|cntry=="BE"|cntry=="CH"|cntry=="DK" ///
|cntry=="FI"|cntry=="FR"|cntry=="GR"|cntry=="IS"|cntry=="NL"|cntry=="NO") 
replace cntryrr=1 if essround==3 & (cntry=="AT"|cntry=="BE"|cntry=="CH"|cntry=="DK" ///
|cntry=="FI"|cntry=="FR"|cntry=="NL"|cntry=="NO") 
replace cntryrr=1 if essround==4 & (cntry=="BE"|cntry=="CH"|cntry=="DK"|cntry=="FI"| ///
cntry=="FR"|cntry=="GR"|cntry=="NL"|cntry=="NO") 
replace cntryrr=1 if essround==5 & (cntry=="BE"|cntry=="CH"|cntry=="DK"|cntry=="FI"|cntry=="FR"| ///
cntry=="GR"|cntry=="NL"|cntry=="NO"|cntry=="SE") 
replace cntryrr=1 if essround==6 & (cntry=="BE"|cntry=="CH"|cntry=="DK"|cntry=="FI"|cntry=="FR"| ///
cntry=="IS"| cntry=="IT"|cntry=="NL"|cntry=="NO"|cntry=="SE") 
replace cntryrr=1 if essround==7 & (cntry=="AT"|cntry=="BE"|cntry=="CH"|cntry=="DK"|cntry=="FI"|cntry=="FR"| ///
cntry=="NL"|cntry=="NO"|cntry=="SE") 
replace cntryrr=1 if essround==8 & (cntry=="AT"|cntry=="BE"|cntry=="CH"|cntry=="FI"|cntry=="FR"| ///
cntry=="IS"|cntry=="IT"|cntry=="NL"|cntry=="NO"|cntry=="SE") 
replace cntryrr=1 if essround==9 & (cntry=="AT"|cntry=="BE"|cntry=="CH"|cntry=="DK"|cntry=="FI"|cntry=="FR"| ///
cntry=="IS"|cntry=="IT"|cntry=="NL"|cntry=="NO"|cntry=="SE") 
replace cntryrr=1 if essround==10 & (cntry=="AT"|cntry=="BE"|cntry=="CH"|cntry=="DE"|cntry=="FI"|cntry=="FR"|cntry== "GR" | ///
cntry=="IS"|cntry=="NO"|cntry=="NL"|"GR"cntry=="PT"|cntry=="SE") 
replace cntryrr=0 if essround==1 & (cntry=="DE"|cntry=="ES"|cntry=="GB"| ///
cntry=="GR"|cntry=="IE"|cntry=="LU"|cntry=="PT"|cntry=="SE") 
replace cntryrr=0 if essround==2 & (cntry=="DE"|cntry=="ES"|cntry=="GB"|cntry=="IE"| ///
cntry=="LU"|cntry=="PT"|cntry=="SE") 
replace cntryrr=0 if essround==3 & (cntry=="DE"|cntry=="ES"|cntry=="GB"|cntry=="IE"| ///
cntry=="PT"|cntry=="SE") 
replace cntryrr=0 if essround==4 & (cntry=="DE"|cntry=="ES"|cntry=="GB"|cntry=="IE"| ///
cntry=="PT"|cntry=="SE") 
replace cntryrr=0 if essround==5 & (cntry=="DE"|cntry=="ES"|cntry=="GB"| ///
cntry=="IE"|cntry=="PT") 
replace cntryrr=0 if essround==6 & (cntry=="DE"|cntry=="ES"|cntry=="GB"| ///
cntry=="IE"|cntry=="PT") 
replace cntryrr=0 if essround==7 & (cntry=="DE"|cntry=="ES"|cntry=="GB"| ///
cntry=="IE"|cntry=="GR"|cntry=="PT"|cntry=="IS"|cntry=="LU") 
replace cntryrr=0 if essround==8 & (cntry=="DE"|cntry=="DK"|cntry=="ES"|cntry=="GB"| ///
cntry=="IE"|cntry=="GR"|cntry=="PT"|cntry=="LU")
replace cntryrr=0 if essround==9 & (cntry=="DE"|cntry=="ES"|cntry=="GB"| ///
cntry=="IE"|cntry=="GR"|cntry=="PT"|cntry=="LU") 
replace cntryrr=0 if essround==10 & (cntry=="DK"|cntry=="ES"|cntry=="GB"| ///
cntry=="IE"|cntry=="IT"|cntry=="LU") 


* Figure 1a: Gender gap for the SD overtime broken down by countryear with and without RR in parliament 
twoway lpolyci ggsdper year if cntryrr==0 , degree(2) level(95) clstyle(p1line) lcol(black) fcolor(gs8*.7) acolor(538rs9%50) alsty(nono)level(95) lwidth(thick) lpattern(solid) yline(0) ysc(off) || lpolyci  ggsdper year if cntryrr==1,  degree(2) level(95)lcol(red) fcolor(red*.7) lp(solid)acolor(538rs9%50) alsty(nono)level(95) lwidth(thick) lpattern(solid) lstyle(none)ytitle("Gender gap for Social Democratic parties") xtitle("")  ///
										   caption(Source: ESS 1-10)  /// 
										   xtitle("") fxsize(50)  ///
										   msymbol (i) graphregion(color(white)) ///
										   ylabel(,nogrid) legend(off) 
graph save "ESS_GGsd_simple", replace

* Figure D2 (Appendix): Balanced sample of countries, simplified Figure - GG for SD*
twoway lpolyci ggsdper year if cntryrr==0 & (cntry=="LU"|cntry=="DE"|cntry=="BE"|cntry=="FR"|cntry=="IT"|cntry=="NL"|cntry=="DK"|cntry=="IE"|cntry=="GB")  , degree(2) level(95)alsty(nono) clstyle(p1line) lcol(black) fcolor(gs8*.7) acolor(538rs9%50) level(95) lwidth(thick) lpattern(solid)   yline(0) ysc(off) || lpolyci  ggsdper year if cntryrr==1 & (cntry=="LU"|cntry=="DE"|cntry=="BE"|cntry=="FR"|cntry=="IT"|cntry=="NL"|cntry=="DK"|cntry=="IE"|cntry=="GB"),  degree(2) level(95) lcol(red)lpattern(solid) alsty(nono) fcolor(red*.7) acolor(538rs9%50) level(95) lwidth(thick) ytitle("Gender gap for Social Democratic parties") xtitle("") ///
										   caption(Source: ESS 1-10)  /// 
										   xtitle("") fxsize(50) ///
										   msymbol (i) graphregion(color(white)) ///
										   ylabel(,nogrid) legend(off) 
graph save "ESS GGsd_balanced_simple", replace

* Figure D1 (Appendix): Gender gap for SD overtime broken down by countryear with and without RR in parliament 
twoway scatter ggsdper year if (cntry=="ES" & cntryrr==1), yline(0) ytitle("") xtitle("") ///
										   caption(Source: Source: ESS1-10)  /// 
										   xtitle("") connect (l) lpattern(solid) ///
										   lcolor(black) msymbol (i)  fxsize(50) ///
										   ylabel(,nogrid) legend(off)  ///
		||scatter ggsdper year if (cntry=="GB" & cntryrr==1), connect (l) lpattern(solid) lcolor(red) msymbol (i) ///
		||scatter ggsdper year if (cntry=="CH" & cntryrr==1), connect (l) lpattern(solid) lcolor(red) msymbol (i) ///
		||scatter ggsdper year if (cntry=="IS" & cntryrr==1), connect (l) lpattern(solid) lcolor(red) msymbol (i) ///
		||scatter ggsdper year if (cntry=="IE" & cntryrr==1), connect (l) lpattern(solid) lcolor(red) msymbol (i) ///
		||scatter ggsdper year if (cntry=="LU" & cntryrr==1), connect (l) lpattern(solid) lcolor(red) msymbol (i) ///
		||scatter ggsdper year if (cntry=="PT" & cntryrr==1), connect (l) lpattern(solid) lcolor(red) msymbol (i) ///
		||scatter ggsdper year if (cntry=="DE" & cntryrr==1), connect (l) lpattern(solid) lcolor(red) msymbol (i) ///
		||scatter ggsdper year if (cntry=="AT" & cntryrr==1), connect (l) lpattern(solid) lcolor(red) msymbol (i) ///
		||scatter ggsdper year if (cntry=="BE" & cntryrr==1), connect (l) lpattern(solid) lcolor(red) msymbol (i) ///
		||scatter ggsdper year if (cntry=="FR" & cntryrr==1), connect (l) lpattern(solid) lcolor(red) msymbol (i) ///
		||scatter ggsdper year if (cntry=="GR" & cntryrr==1), connect (l) lpattern(solid) lcolor(red) msymbol (i) ///
		||scatter ggsdper year if (cntry=="IT" & cntryrr==1), connect (l) lpattern(solid) lcolor(red) msymbol (i) ///
		||scatter ggsdper year if (cntry=="NL" & cntryrr==1), connect (l) lpattern(solid) lcolor(red) msymbol (i) ///
		||scatter ggsdper year if (cntry=="SE" & cntryrr==1), connect (l) lpattern(solid) lcolor(red) msymbol(i) ///
		||scatter ggsdper year if (cntry=="NO" & cntryrr==1), connect (l) lpattern(solid) lcolor(red) msymbol (i) ///
		||scatter ggsdper year if (cntry=="FI" & cntryrr==1), connect (l) lpattern(solid) lcolor(red) msymbol (i) ///
		||scatter ggsdper year if (cntry=="DK" & cntryrr==1), connect (l) lpattern(solid) lcolor(red) msymbol (i) ///
		||scatter ggsdper year if (cntry=="CH" & cntryrr==0), connect (l) lpattern(solid) lcolor(black) msymbol (i) ///
		||scatter ggsdper year if (cntry=="IS" & cntryrr==0), connect (l) lpattern(solid) lcolor(black) msymbol (i) ///
		||scatter ggsdper year if (cntry=="GB" & cntryrr==0), connect (l) lpattern(solid) lcolor(black) msymbol (i) ///
		||scatter ggsdper year if (cntry=="IE" & cntryrr==0), connect (l) lpattern(solid) lcolor(black) msymbol (i) ///
		||scatter ggsdper year if (cntry=="LU" & cntryrr==0), connect (l) lpattern(solid) lcolor(black) msymbol (i) ///
		||scatter ggsdper year if (cntry=="PT" & cntryrr==0), connect (l) lpattern(solid) lcolor(black) msymbol (i) ///
		||scatter ggsdper year if (cntry=="DE" & cntryrr==0), connect (l) lpattern(solid) lcolor(black) msymbol (i) ///
		||scatter ggsdper year if (cntry=="AT" & cntryrr==0), connect (l) lpattern(solid) lcolor(black) msymbol (i) ///
		||scatter ggsdper year if (cntry=="BE" & cntryrr==0), connect (l) lpattern(solid) lcolor(black) msymbol (i) ///
		||scatter ggsdper year if (cntry=="FR" & cntryrr==0), connect (l) lpattern(solid) lcolor(black) msymbol (i) ///
		||scatter ggsdper year if (cntry=="GR" & cntryrr==0), connect (l) lpattern(solid) lcolor(black) msymbol (i) ///
		||scatter ggsdper year if (cntry=="IT" & cntryrr==0), connect (l) lpattern(solid) lcolor(black) msymbol (i) ///
		||scatter ggsdper year if (cntry=="NL" & cntryrr==0), connect (l) lpattern(solid) lcolor(black) msymbol (i) ///
		||scatter ggsdper year if (cntry=="SE" & cntryrr==0), connect (l) lpattern(solid) lcolor(black) msymbol(i) ///
		||scatter ggsdper year if (cntry=="NO" & cntryrr==0), connect (l) lpattern(solid) lcolor(black) msymbol (i) ///
		||scatter ggsdper year if (cntry=="FI" & cntryrr==0), connect (l) lpattern(solid) lcolor(black) msymbol (i) ///
		||scatter ggsdper year if (cntry=="DK" & cntryrr==0), connect (l) lpattern(solid) lcolor(black) msymbol (i) ///
		||scatter ggsdper year if (cntry=="ES" & cntryrr==0), connect (l) lpattern(solid) lcolor(black) msymbol (i) ///
		|| lpolyci    ggsdper year if cntryrr==0 ,  degree(2)  clstyle(p1line) lcol(black) fcolor(gs8*.7)alsty(nono) acolor(538rs9%50) level(95) lwidth(thick) lpattern(solid)  ///
		|| lpolyci    ggsdper year if cntryrr==1 ,  degree(2)  clstyle(p1line) alsty(nono)lcol(red) fcolor(red*.7) acolor(538rs9%50) level(95) lwidth(thick) lpattern(solid)  ysc(off)
graph save "ESS GGsd w wo RR", replace


* Figure 1b: Gender gap for the RR over Year

gen ggrrper = ggrrunique1*100  

twoway lpolyci ggrrper year , degree(2) level(95) clstyle(p1line)  yline(0)  ysc(off) ytitle("Gender gap for FRPs") xtitle("") ///
										   caption(Source: ESS 1-10)  /// 
										   xtitle("") fxsize(50) ///
										   msymbol (i) graphregion(color(white)) ///
										   ylabel(,nogrid) legend(off) 
graph save "ESS_GGrr_simple", replace


*Figure D2 (Appendix): simplified figure - gender gap for rr only 9 countries 
twoway lpolyci ggrrper year if (cntry=="LU"|cntry=="DE"|cntry=="BE"|cntry=="FR"|cntry=="IT"|cntry=="NL"|cntry=="DK"|cntry=="IE"|cntry=="GB"), degree(2) level(95) clstyle(p1line)  yline(0) ytitle("Gender gap for FRPs")  ysc(off) xtitle("") ///
										   caption(Source: ESS 1-10)  /// 
										   xtitle("") fxsize(50) ///
										   msymbol (i) graphregion(color(white)) ///
										   ylabel(,nogrid) legend(off) 
graph save "ESS_GGrr_balance_simple", replace

* Figure D1 (Appendix): Gender gap for the RR over Year
twoway scatter ggrrper year if cntry=="ES", yline(0) ytitle("") xtitle("") ///
										   caption(Source: Source: ESS1-10)  /// 
										   xtitle("") connect (l) lpattern("__...")  fxsize(50) ///
										   lcolor(black) msymbol (i) graphregion(color(white)) ///
										   ylabel(,nogrid) legend(off) ///
		||scatter ggrrper year if cntry=="GB", connect (l) lpattern(solid) lcolor(black) msymbol (i) ///
		||scatter ggrrper year if cntry=="IE", connect (l) lpattern(dot) lcolor(black) msymbol (i) ///
		||scatter ggrrper year if cntry=="LU", connect (l) lpattern("___--") lcolor(black) msymbol (i) ///
		||scatter ggrrper year if cntry=="PT", connect (l) lpattern(shortdash_dot_dot) lcolor(black) msymbol (i) ///
		||scatter ggrrper year if cntry=="DE", connect (l) lpattern(shortdash) lcolor(black) msymbol (i) ///
		||scatter ggrrper year if cntry=="AT", connect (l) lpattern(longdash) lcolor(black) msymbol (i) ///
		||scatter ggrrper year if cntry=="BE", connect (l) lpattern(dash) lcolor(black) msymbol (i) ///
		||scatter ggrrper year if cntry=="CH", connect (l) lpattern("...-...-") lcolor(black) msymbol (i) ///
		||scatter ggrrper year if cntry=="FR", connect (l) lpattern(longdash_dot) lcolor(black) msymbol (i) ///
		||scatter ggrrper year if cntry=="GR", connect (l) lpattern(dash_dot) lcolor(black) msymbol (i) ///
		||scatter ggrrper year if cntry=="IT", connect (l) lpattern("-..-..") lcolor(black) msymbol (i) ///
		||scatter ggrrper year if cntry=="NL", connect (l) lpattern("-...-...") lcolor(black) msymbol (i) ///
		||scatter ggrrper year if cntry=="SE", connect (l) lpattern("--..--..") lcolor(black) msymbol(i) ///
		||scatter ggrrper year if cntry=="NO", connect (l) lpattern("___..___") lcolor(black) msymbol (i) ///
		||scatter ggrrper year if cntry=="IS", connect (l) lpattern("__-__-") lcolor(black) msymbol (i) ///
		||scatter ggrrper year if cntry=="FI", connect (l) lpattern("___ ___") lcolor(black) msymbol (i) ///
		||scatter ggrrper year if cntry=="DK", connect (l) lpattern("___.___") lcolor(black) msymbol (i) ///
		||lpolyci ggrrper year ,   degree(3) clstyle(p1line) level(95) ysc(off)
graph save "ESS GG RR", replace


		
/*3. Save dataset with party families and calculated gender gaps */

save "ESS1-10_modified", replace
log close



